/****************************************
 ****************************************
 **   This document written by CTonk.  **
 **        ctonk87@hotmail.com         **
 ****************************************
 ****************************************/

// logfile.cpp

#ifndef CPP_LOGFILE
#define CPP_LOGFILE

#include "logfile.h"

void log( Logtype type, std::string& message )
{
	ofstream log;
	Time::clock Clock;

	switch ( type )
	{
		case server: log.open( "Log/server_log.txt", ofstream::app ); break;
		case world: log.open( "Log/world_log.txt", ofstream::app ); break;
		case event: log.open( "Log/event_log.txt", ofstream::app ); break;
		default: log.open( "Log/default_log.txt", ofstream::app ); break;
	}

	log << "\n\n" << Clock.GetDate() << ' ' << Clock.GetTime() << "\n\t" << message;
	log.close();
	return;
}

void log( Logtype type, char* message )
{
	ofstream log;
	Time::clock Clock;

	switch ( type )
	{
		case server: log.open( "Log/server_log.txt", ofstream::app ); break;
		case world: log.open( "Log/world_log.txt", ofstream::app ); break;
		case event: log.open( "Log/event_log.txt", ofstream::app ); break;
		default: log.open( "Log/default_log.txt", ofstream::app ); break;
	}

	log << "\n\n" << Clock.GetDate() << ' ' << Clock.GetTime() << "\n\t" << message;
	log.close();
	return;
}

void log( Logtype type, const char* message )
{
	ofstream log;
	Time::clock Clock;

	switch ( type )
	{
		case server: log.open( "Log/server_log.txt", ofstream::app ); break;
		case world: log.open( "Log/world_log.txt", ofstream::app ); break;
		case event: log.open( "Log/event_log.txt", ofstream::app ); break;
		default: log.open( "Log/default_log.txt", ofstream::app ); break;
	}

	log << "\n\n" << Clock.GetDate() << ' ' << Clock.GetTime() << "\n\t" << message;
	log.close();
	return;
}

void log( Creature* ch, std::string& message )
{
	std::string file;
	std::string buf;
	Time::clock Clock;
	file = "Log/plogs/";
	file += ch->GetName();
	file += "(log).txt";

	buf << '\n' << Clock.GetDate() << ' ' << Clock.GetTime() << " (" << ch->GetSocket()->GetSocketIP()
		<< ' ' << ch->GetSocket()->GetDescriptor() << ")\n\t" << message;

	ofstream log( file.data(), ofstream::app );
	log << buf;
	log.close();
	return;
}

void log( Creature* ch, char* message )
{
	std::string file;
	std::string buf;
	Time::clock Clock;
	file = "Log/plogs/";
	file += ch->GetName();
	file += "(log).txt";

	buf << '\n' << Clock.GetDate() << ' ' << Clock.GetTime() << " (" << ch->GetSocket()->GetSocketIP()
		<< ' ' << ch->GetSocket()->GetDescriptor() << ")\n\t" << message;

	ofstream log( file.data(), ofstream::app );
	log << buf;
	log.close();
	return;
}

void log( Creature* ch, const char* message )
{
	std::string file;
	std::string buf;
	Time::clock Clock;
	file = "Log/plogs/";
	file += ch->GetName();
	file += "(log).txt";

	buf << '\n' << Clock.GetDate() << ' ' << Clock.GetTime() << " (" << ch->GetSocket()->GetSocketIP()
		<< ' ' << ch->GetSocket()->GetDescriptor() << ")\n\t" << message;

	ofstream log( file.data(), ofstream::app );
	log << buf;
	log.close();
	return;
}



#endif // #ifndef CPP_LOGFILE